﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Estimate.Common.DBFieldTypes;
using Estimate.Common.Repository;
using Estimate.Common.Estimate;
using Newtonsoft.Json;

namespace Estimate.Reports
{
    /// <summary>
    /// 核查表数据报表类
    /// </summary>
    public class CheckListDataReport
    {
        private FullInfoReport memberReportScore;// 得分对象
        private FullInfoReport standardReportScore;// 标准评分对象
        ExecutionStatus exeStatus;//程序执行状态
        CheckListDataResult Result = new CheckListDataResult();
        protected string _connectionString;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="ConnectionString"></param>
        /// <param name="tableName">数据表类型</param>
        /// <param name="tid">程序执行任务号</param>
        public CheckListDataReport(string ConnectionString,string tableName, string tid)
        {
            _connectionString = ConnectionString;
            if (tid != "")
                exeStatus = new ExecutionStatus(tid);

            ForeRepository DataProvider = null;// 获取semi的数据检索对象

             switch (tableName)
             {
                 case "city": //城镇预报
                     DataProvider = ForeRepositoryFactory.NormalCityForeRepository(_connectionString);
                     break;
                 case "zd"://指导站预报
                     DataProvider = ForeRepositoryFactory.StSiteForeRepository(_connectionString);
                     break;
                 case "js": //降水等值线
                     DataProvider = ForeRepositoryFactory.RainForeRepository(_connectionString);
                     break;
                 case "zyt"://国家局下
                     DataProvider = ForeRepositoryFactory.ZytCityForeRepository(_connectionString);
                     break;
                 default:
                     break;
             }

             memberReportScore = new FullInfoReport(_connectionString, DataProvider);
             memberReportScore.CulculateAllResult = true;
             memberReportScore.CulculateDeviationResult = false;

             standardReportScore = new FullInfoReport(_connectionString, ForeRepositoryFactory.ZytCityForeRepository(_connectionString));
             standardReportScore.CulculateAllResult = true;
             standardReportScore.CulculateDeviationResult = false;

        }

        public void PrepareData(DateTime beginDate, DateTime endDate, ForeSendpointType[] sendpoints, ForeSpanType[] wthSpans, ForeSpanType[] tempSpans, ForeSemiType semitype)
        {
            try
            {
                if (exeStatus != null)
                {
                    exeStatus.TotalStep = (wthSpans.Length + tempSpans.Length) * 2;
                    exeStatus.SetMessage("memberReportScore", "得分计算程序正在计算标准得分");
                }

                memberReportScore.PrepareData(beginDate, endDate, semitype, wthSpans, tempSpans, sendpoints);

                if (exeStatus != null)
                {
                    exeStatus.DeleteMessage("memberReportScore");
                    exeStatus.SetMessage("standardReportScore", "得分计算程序正在计算技巧值评分标准");
                }


                standardReportScore.PrepareData(beginDate, endDate, semitype, wthSpans, tempSpans, sendpoints);

                if (exeStatus != null) exeStatus.DeleteMessage("standardReportScore");
            }
            catch (Exception ex)
            {
                Result.success = false.ToString();
                Result.msg = ex.Message;
            }
        }

          /// <summary>
        /// 获取核查表数据字符串
        /// </summary>
        /// <returns></returns>
        public string GetCheckListDataString()
        {
            Result.result.Add("data", memberReportScore.ToResult(standardReportScore, ""));
            return JsonConvert.SerializeObject(Result);
        }
    }


    public class CheckListDataResult
    {
        public string success = true.ToString();
        public string msg = "";
        public Dictionary<string, object> result = new Dictionary<string, object>();

        public CheckListDataResult()
        {
           
        }
    }
    
}
